/*
脚本说明:权限维护，添加authid与scriptid对应关系。
程序员:
*/

//脚本唯一关键字,通过该关键字找到对应脚本，每个脚本必须有该描述。
var v_script_id = 'authscript_3';
//脚本状态,0:该脚本不许执行，1:该脚本可以执行
var v_status = '1';

//脚本逻辑写在run语句之间
if (run && action.getSession().getAttribute("user").rolekind==2){
	var authid = action.form.getInteger('authid');
	var scriptid = action.form.getString('scriptid');
	var checkids = action.form.getString('checkids');
	var arr_checkids = checkids.split(',');
	var sql = '';
	for (i=0; i<arr_checkids.length; i++){
		sql = "select count(id) from h_auth_scriptactions where authid = " + authid + 
			"and scid = '" + scriptid + "' and authkindid = " + arr_checkids[i];
		if(action.dbUtil.getSampleIntegerValue(sql) == 0 ){
			sql = "insert into h_auth_scriptactions values( h_auth_scriptactions_seq.nextval, " + 
				authid + ",'" + scriptid + "'," + arr_checkids[i] + ")";
			if(action.dbUtil.update("",sql)==0) 
			{
				action.errorCode = 2;//数据库操作失败
				action.retString = '数据库操作失败   ' ;//错误文字说明
			};
		}
	}

	//刷新权限分配缓存
	if (action.errorCode ==0){
		com.handy.plugin.auth.TAuthCache.getInstance().loadAuthScriptAction();
		//com.handy.plugin.auth.TAuthCache.getInstance().loadAuthScriptKindAction();
	}
}